
//注册发送验证码
function pushCode(){
	var phone =$("#phone").val();
	
	if(phone==''){
		alert('请输入一个手机号');
		return;
	}
			$.ajax({  
		    url:'/baby/sys/pushCode',// 跳转到 action  
		    data:{
				 phonNum:phone
		    },  
		    type:'post',  
		    cache:false,  
		    dataType:'json',  
		    success:function(data){ 
		    	 console.log(data);  
		        if(data.code =="2000" ){ 
		            alert(data.message);
		         //   window.location.reload();
		        }else{  
		           
		            alert(data.message);
		        }  
		    }, error : function() {      
		          

		    }  
		});
	}

//注册
function register(){
 	
	var phone =$("#phone").val();
	var name =$("#name").val();
	var pwd =$("#pwd").val();
	var isCheck =$("#isCheck").prop("checked");

	var password =$("#password").val();
	var pushCode =$("#pushCode").val();

//	console.log("xxxx"+phone+name+pwd+password+pushCode);
	
	if(phone==''|| name==''|| pwd==''||password==''||pushCode==''){
		alert('信息不完整');
		return;
	}
//	if(pwd!=password){
//		alert("两次密码不一致");
//		return;
//	}
	if($("#isCheck").prop("checked")){
		$.ajax({  
		    url:'/baby/sys/sysAddUser',// 跳转到 action  
		    data:{
				 phonNum:phone,
				 pwd:password,
				 checkNum:pushCode,
				 name:name
		    },  
		    type:'post',  
		    cache:false,  
		    dataType:'json',  
		    success:function(data){ 
		    	alert(data)
		    	console.log(">>>>"+data);  
		        if(data.code =="2000" ){ 
		            alert(data.message);
		         //   window.location.href = "login.html"
		        }else{  
		           
		            alert(data.message);
		        }  
		    }, error : function() {      
		    }  
			
		});
	}
		
} 
 
//登录
function syslogin(redirectURL){
	var phone =$("#userPhone").val();
	var pwd=$("#pwd").val();
	// alert(redirectURL);
	var isMemory=$("#isCheck").prop("checked")? 1:0;
	// alert(isMemory);
	if(phone==''|| pwd==''){
		alert('手机或密码不能为空');
		return;
	}
			$.ajax({  
		    url:'/baby/sys/login',// 跳转到 action  
		    data:{
				 username:phone,
				 password:pwd,
				 isMemory:isMemory
		    },  
		    type:'post',   
		    cache:false,  
		    dataType:'json',  
		    success:function(data){ 
		        if(data.code =="2000" ){ 
		        	console.log(data);
		            alert(data.message);
		          //  setCookie("username",encodeURI(data.data.userName));
		          if(redirectURL===undefined ||redirectURL==='null' ){
		          	window.location.reload();
		          }else{
		          window.location.href=redirectURL;	
		          }
		           
		        }else{  
		           
		            alert(data.message);
		        }  
		    }, error : function() {      
		          

		    }  
		});
}


	function getUser(){
		$.ajax({
			url: '/baby/sys/getUserInfo', // 跳转到 action  
			data: {},
			type: 'post',
			cache: false,
			dataType: 'json',
			success: function(data){
				if(data.code == "2000"){
					console.log(data);
					$("#lg").html("").css({"background-color":"transparent"});
					$('#ou').hide();//未登录的隐藏
					$("#lu").show();//登录的显示
					var imgurl='' 
					// alert(data.data.userHeadPic.length);
					if(data.data.userHeadPic.length<54){
						imgurl=	'img/login.png';
					}else{
						imgurl=data.data.userHeadPic;
					}
					
					$("#ln").attr("src",imgurl);
					//setCookie("username", encodeURI(data.data.userName));
					//console.log(decodeURI(data.data.userName));
//					window.location.href = 'index.html'
					// window.location.reload();
				}else{
					$('#lu').hide();//登录的隐藏
					$("#ou").show();//未登录的显示
					// alert(data.message);
					console.log(data);
				}
			},
			error: function(){
				// view("异常！");  
				
			}
		});
	}


//找回密码
//发送验证码
function findPushCode(){
	var phone =$("#phonNum").val();
	
	if(phone==''){
		alert('请输入一个手机号');
		return;
	}
		$.ajax({  
		    url:'/baby/retPwd/pushCode',// 跳转到 action  
		    data:{
				phonNum:phone
		    },  
		    type:'post',  
		    cache:false,  
		    dataType:'json',  
		    success:function(data){ 
		    	 console.log(data);  
		        if(data.code =="2000" ){ 
		            alert(data.message);
		        }else{  
		            alert(data.message);
		        }  
		    }, error : function() {      
		    }  
		});
	}
//找回密码

function findPwd(){
	var phone =$("#phonNum").val();
	var checkNum =$("#checkNum").val();
	var password =$("#password").val();
	var pwd =$("#pwd").val();
	
//	if(phone=='' ||checkNum==''||password==''|| pwd==''){
//		alert('信息不完整');
//		return;
//	}
	if(pwd != password){
		alert("两次密码不一致");
		return;
	}
		$.ajax({  
		    url:'/baby/retPwd/upUserPwd',// 跳转到 action  
		    data:{
				 phonNum:phone,
				 checkNum:checkNum,
				 password:password
		    },  
		    type:'post',  
		    cache:false,  
		    dataType:'json',  
		    success:function(data){ 
		    	 console.log(data);  
		        if(data.code =="2000" ){ 
		            alert(data.message);
//		           	window.location.reload();
		        	window.location.href = "login.html";
		        }else{
		            alert(data.message);
		        }  
		    }, error : function() {      
		    }  
		});
	}
